﻿'Imports System
'Imports System.Collections.Generic
'Imports System.Text
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
'Imports Microsoft.Xna.Framework.Content

Public Class SkyBox
    Inherits GameObject

    Private mSkyUp As Texture2D
    Private mSkyDown As Texture2D
    Private mSkyLeft As Texture2D
    Private mSkyRight As Texture2D
    Private mSkyFront As Texture2D
    Private mSkyBack As Texture2D

    Private name As String = "clearblue"
    Private mGameManager As GameManager

    Public Sub New(ByVal GameManager As GameManager)
        MyBase.New(GameManager)
        Models.Add(New MyModel(GameManager.Game.Content.Load(Of Model)("skybox")))
        Scale = New Vector3(50.0F)
    End Sub

    Public Overrides Sub LoadContent()
        MyBase.LoadContent()
        LoadTextures(name)
    End Sub

    Public Sub LoadTextures(ByVal skyName As String)

        name = skyName

        mSkyBack = GameManager.Game.Content.Load(Of Texture2D)("skybox\" + skyName + "_bk")
        mSkyFront = GameManager.Game.Content.Load(Of Texture2D)("skybox\" + skyName + "_ft")
        mSkyDown = GameManager.Game.Content.Load(Of Texture2D)("skybox\" + skyName + "_dn")
        mSkyUp = GameManager.Game.Content.Load(Of Texture2D)("skybox\" + skyName + "_up")
        mSkyRight = GameManager.Game.Content.Load(Of Texture2D)("skybox\" + skyName + "_lt")
        mSkyLeft = GameManager.Game.Content.Load(Of Texture2D)("skybox\" + skyName + "_rt")

    End Sub

    Public Overrides Sub Draw(ByVal elapsedSeconds As Single, ByVal camera As Camera3D)
        CalculateCurrentModel(camera)

        'GameManager.Game.GraphicsDevice.RenderState.FogEnable = False
        'GameManager.Game.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace
        'GameManager.Game.GraphicsDevice.RasterizerState.CullMode = CullMode.CullCounterClockwiseFace

        '   GameManager.Game.GraphicsDevice.RenderState.DepthBufferEnabled = False

        Position = camera.Position

        For Each mesh As ModelMesh In Model.Model.Meshes

            For Each meshEffect As BasicEffect In mesh.Effects
                meshEffect.World = World
                meshEffect.View = camera.View
                meshEffect.Projection = camera.Projection
                meshEffect.TextureEnabled = True
                meshEffect.LightingEnabled = False


                Select Case mesh.Name
                    Case "up"
                        meshEffect.Texture = mSkyUp
                        Exit Select
                    Case "left"
                        meshEffect.Texture = mSkyLeft
                        Exit Select
                    Case "right"
                        meshEffect.Texture = mSkyRight
                        Exit Select
                    Case "back"
                        meshEffect.Texture = mSkyBack
                        Exit Select
                    Case "front"
                        meshEffect.Texture = mSkyFront
                        Exit Select
                    Case "down"
                        meshEffect.Texture = mSkyDown
                        Exit Select
                End Select

                meshEffect.DiffuseColor = Vector3.One
                ' meshEffect.CommitChanges()
            Next

            mesh.Draw()
        Next

    End Sub
End Class